package org.itboys.mobile.service.mongo.weixin.count;

import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.dto.count.MdlCountDto;
import org.itboys.mobile.service.mongo.web.member.SundayMemberService;
import org.itboys.mobile.service.mongo.weixin.address.SundayWeixinAddressService;
import org.itboys.mobile.service.mongo.weixin.cart.MdlWeixinCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2017/12/7
 * 描述：迈迪龙_微信_结算
 */
@Service
public class MdlWeixinCountService {
    @Autowired
    private MdlWeixinCartService cartService;
    @Autowired
    private SundayMemberService memberService;
    @Autowired
    private SundayWeixinAddressService addressService;
    /**
     * 购物车结算。
     * @param memberId
     * @param cartIds
     * @return
     */
    public MdlCountDto countCart(Long memberId, List<Long> cartIds, Integer cartType,Integer sendType){
            MdlCountDto countDto=cartService.getCart(memberId,cartIds,cartType);
        //加载默认地址
        BigDecimal totalAmount = countDto.getTotalAmount();
        BigDecimal payAmount = countDto.getPayAmount();
        countDto.setSendType(sendType);
        //Map<String,Object> result = expressModeService.matching(payAmount.doubleValue());
        //待补充运费信息
        Map<String,Object> result=new HashMap<String,Object>();
        BigDecimal sendAmount =(BigDecimal)result.get("sendAmount");
        String sendMsg= (String)result.get("sendMsg");
        totalAmount=totalAmount.add(sendAmount);
        payAmount=payAmount.add(sendAmount);
        countDto.setSendAmount(sendAmount);
        countDto.setSendMsg(sendMsg);


        countDto.setTotalAmount(totalAmount);
        countDto.setPayAmount(payAmount);
        return countDto;

    }

    /**
     * 立即购买结算
     * @param memberId
     * @param productId
     * @param number
     * @return
     */
    public MdlCountDto countBuyNow(Long memberId,Long productId,Integer number,Integer sendType){
        List<Long> productIds =new ArrayList<Long>();
        productIds.add(productId);
        List<Integer> numbers =new ArrayList<Integer>();
        numbers.add(number);
        List<Long> cartIds= cartService.addCart(memberId,productIds ,numbers, SundayCommonConstants.cart_type_buy_now);
        return countCart(memberId,cartIds,SundayCommonConstants.cart_type_buy_now,sendType);
    }

}
